package com.googlecode.transmutant

import static org.junit.Assert.*;

import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
import org.junit.Test
import org.codehaus.groovy.runtime.InvokerHelper

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Method
import java.util.HashMap;
import java.util.List;

class StepValidatorTest {
	
	@Test
	public void testStepOrderHigh() {
		def step = new ThreeStepSame()
		def stepper = new StepValidator()
		try {
			stepper.step step
			fail()
		} catch (e) {
			def message = "@Step methods should have unique order values"
			assert e.message == message
		}
	}
	
	@Test
	public void testMultipleInFieldssOfSameName() throws Exception {
		def step = new MultiInFieldStep()
		def bos = new ByteArrayOutputStream()
		System.setOut(new PrintStream(bos))
		new StepValidator().step(step)
		assert bos.toString().contains("WARN com.googlecode.transmutant.StepValidator  - duplicate @In names found")
	}
	
	@Test
	public void testMultipleOutFieldsOfSameName() throws Exception {
		def step = new MultiOutFieldStep()
		def bos = new ByteArrayOutputStream()
		System.setOut(new PrintStream(bos))
		new StepValidator().step(step)
		assert bos.toString().contains("WARN com.googlecode.transmutant.StepValidator  - duplicate @Out names found")
	}
	
	@Test
	public void testMultipleOutsOfSameNameWithMethod() throws Exception {
		def step = new OutFieldWithOutStepOfSameName()
		def bos = new ByteArrayOutputStream()
		System.setOut(new PrintStream(bos))
		new StepValidator().step(step)
		assert bos.toString().contains("WARN com.googlecode.transmutant.StepValidator  - duplicate @Out names found")
	}
}